﻿using B.S.Medical.Api.Read.Application.Command.DoctorSchedule;
using B.S.Medical.Api.Read.DTOS;
using B.S.Medical.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;

namespace B.S.Medical.Api.Read.Controllers.DoctorSchedule
{
    /// <summary>
    /// 医生排班控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DoctorScheduleController : ControllerBase
    {
        private readonly IMediator mediator;

        public DoctorScheduleController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 获取医生排班某天
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<DoctorDayScheduleDto>> GetDoctorDaySchedule([FromQuery]GetDoctorDayScheduleCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取某天医生分页
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiPageing<DoctorScheduleDto>> GetDoctorSchedule([FromQuery]GetDoctorScheduleCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 根据科室ID获取有排班医生列表及号源信息
        /// </summary>
        /// <param name="departmentId">科室ID</param>
        /// <param name="date">排班日期（可选，默认为当天）</param>
        /// <returns>医生排班和号源信息列表</returns>
        [HttpGet]
        public async Task<ApiResult<List<DoctorScheduleInfoDTO>>> GetDoctorsByDepartment(int departmentId, DateTime? date = null)
        {
            var command = new GetDoctorsByDepartmentCommand
            {
                DepartmentId = departmentId,
                ScheduleDate = date ?? DateTime.Today
            };
            
            return await mediator.Send(command);
        }
    }
}
